package com.zx.controller;


import com.zx.common.TableId;
import com.zx.service.IECommerceAddressService;
import com.zx.vo.AddressInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressController {


    @Autowired
    private IECommerceAddressService addressService;

    /**
     * 新增地址
     * @param addressInfo
     * @return
     */
    @PostMapping("/create-address-info")
    public TableId createAddress(@RequestBody AddressInfo addressInfo){
        return addressService.creatAddressInfo(addressInfo);
    }

    /**
     * 获取当前用户的地址信息
     * @return
     */
    @GetMapping("/get-current-address")
    public AddressInfo getCurrentUserAddressInfo(){
        return addressService.getCurrentAddressInfoByCurrentUserId();
    }


    /**
     * 根据传过来的地址
     * @param id
     * @return
     */
    @GetMapping("/get-address-by-id/{id}")
    public AddressInfo getAddressInfoById(@PathVariable("id") Long id){
        return addressService.getAddressInfoById(id);
    }


    @PostMapping("/get-address-by-tableId")
    public AddressInfo getAddressInfoByTableId(@RequestBody TableId tableId){
        return addressService.getAddressInfoByTableId(tableId);
    }
}
